t is initialized to 0, t == 5 will always be evaluated to be false, so your for loop will never run.

update

for (t = 0; t == 5; t++) {

to

for (t = 0; t < 5; t++) {

for Statement

Executes a statement repeatedly until the condition becomes false.

for ( init-expression ; cond-expression ; loop-expression )

      statement;
Answer from billz on Stack Overflow
🌐
Reddit
reddit.com › r/cplusplus › c++ for loop does not work
r/Cplusplus on Reddit: c++ for loop does not work

How is the function being called? What does "does not work" mean? Do you have a compilation error? If so, what is it? Does the program crash? Hang? Does the program give the wrong results? If so, what is the data, what results are you expecting, and what results do you get?

🌐
Cppreference
en.cppreference.com › w › cpp › language › for.html
for loop - cppreference.com
Conditionally executes a statement repeatedly, where the statement does not need to manage the loop condition. A condition can either be an expression or a simple declaration. If it can be syntactically resolved as an expression, it is treated as an expression.
🌐
W3Schools
w3schools.com › cpp › cpp_for_loop.asp
C++ For Loop
When you know exactly how many times you want to loop through a block of code, use the for loop instead of a while loop: for (statement 1; statement 2; statement 3) { // code block to be executed } Statement 1 is executed (one time) before the execution of the code block.
🌐
GeeksforGeeks
geeksforgeeks.org › c++ › cpp-for-loop
for Loop in C++ - GeeksforGeeks
08:57
In the above code, we use a range-based ... for loop where you need to manually manage the index and loop condition. C++ for_each loop is not a loop but an algorithm that mimics the range based for loop....
Published: July 12, 2025
🌐
Stack Overflow
stackoverflow.com › questions › 24956423 › c-for-loop-not-running
C++ - for loop not running - Stack Overflow

t is initialized to 0, t == 5 will always be evaluated to be false, so your for loop will never run.

update

for (t = 0; t == 5; t++) {

to

for (t = 0; t < 5; t++) {

for Statement

Executes a statement repeatedly until the condition becomes false.

for ( init-expression ; cond-expression ; loop-expression )

      statement;
Answer from billz on stackoverflow.com
🌐
Florida A&M University
web1.eng.famu.fsu.edu › ~haik › met.dir › hcpp.dir › notes.dir › cppnotes › node45.html
for Loop
An important point about the for loops is that the conditional expression is always tested at the top of the loop. This means that the code inside the loop may not be executed at all if the condition is false to begin with.
🌐
Cppreference
en.cppreference.com › w › cpp › language › range-for.html
Range-based for loop (since C++11) - cppreference.com
Used as a more readable equivalent to the traditional for loop operating over a range of values, such as all elements in a container. The above syntax produces code equivalent to the following except for the lifetime expansion of temporaries of range-initializer (see below)(since C++23) (the variables and expressions wrapped in /* */ are for exposition only): range-initializer is ...
🌐
Stack Overflow
stackoverflow.com › questions › 37602057 › why-isnt-a-for-loop-a-compile-time-expression
c++ - Why isn't a for-loop a compile-time expression? - Stack Overflow

Here's a way to do it that does not need too much boilerplate, inspired from http://stackoverflow.com/a/26902803/1495627 :

template<std::size_t N>
struct num { static const constexpr auto value = N; };

template <class F, std::size_t... Is>
void for_(F func, std::index_sequence<Is...>)
{
  using expander = int[];
  (void)expander{0, ((void)func(num<Is>{}), 0)...};
}

template <std::size_t N, typename F>
void for_(F func)
{
  for_(func, std::make_index_sequence<N>());
}

Then you can do :

for_<N>([&] (auto i) {      
  std::get<i.value>(t); // do stuff
});

If you have a C++17 compiler accessible, it can be simplified to

template <class F, std::size_t... Is>
void for_(F func, std::index_sequence<Is...>)
{
  (func(num<Is>{}), ...);
}
Answer from Jean-Michaël Celerier on stackoverflow.com
🌐
GeeksforGeeks
geeksforgeeks.org › c++ › cpp-loops
Loops in C++ - GeeksforGeeks
05:03
Your All-in-One Learning Portal: GeeksforGeeks is a comprehensive educational platform that empowers learners across domains-spanning computer science and programming, school education, upskilling, commerce, software tools, competitive exams, and more.
Published: January 13, 2017
Find elsewhere
🌐
Stack Overflow
stackoverflow.com › questions › 19235889 › c-for-loop-with-no-conditions
C++ for loop with no conditions - Stack Overflow

This is an infinite loop. Any of the three parts of a for loop (initialization, condition and increment) can be missing. Specifically, if the condition in a for loop is missing, it is treated as being true. So it is equivalent to while(1) { ... }.

Answer from Gavin Smith on stackoverflow.com
🌐
W3Schools
w3schools.com › cpp › cpp_while_loop.asp
C++ While Loop
In the example below, the code in the loop will run, over and over again, as long as a variable (i) is less than 5: int i = 0; while (i < 5) { cout << i << "\n"; i++; } Try it Yourself » · Note: Do not forget to increase the variable used in the condition (i++), otherwise the loop will never end!
🌐
Stack Overflow
stackoverflow.com › questions › 44213471 › expected-expression-error-in-simple-for-loop-c
Expected expression error in simple for loop C - Stack Overflow

If you are trying to typecast, you must do:

(char)x;

Not

char(x);
Answer from Sachin Bharadwaj S on stackoverflow.com
🌐
Cplusplus
cplusplus.com › forum › unices › 234486
Keep getting 'Expected Expression' error - C++ Forum
Here is my code it is written on Xcode on mac. I keep getting the 'Expected Expression' error message and Expected ')' message. Pls help. Thanks! It occurs in the line where it starts For (i = 0; i <3; i++;); #include<stdio.h> #include <unistd.h> int main() { int i; For (i = 0; i < 3; i++;); fork(); printf("Hello World\n"); return 0; } ... For (i = 0; i < 3; i++;); 1. Case matters. It's "for", not ...
🌐
Learn C++
learncpp.com › cpp-tutorial › for-statements
8.10 — For statements – Learn C++
We’ll cover the classic for-statement ... for loops (for-each)) once we’ve covered some other prerequisite topics. The for-statement looks pretty simple in abstract: for (init-statement; condition; end-expression) statement; The easiest way to initially understand how a for-statement works is to convert it into an equivalent while-statement: { // note the block ...
🌐
Codecademy
codecademy.com › article › cpp-for-loop
What is a for Loop in C++? | Codecademy
Learn how to use a `for` loop in C++ with syntax, examples, and use cases. Understand nested and range-based `for` loops and their real-world applications.
🌐
Stack Overflow
stackoverflow.com › questions › 79349189 › can-not-understand-for-loops
c++ - Can not understand for loops - Stack Overflow
I’m struggling to understand the code my Senior sent me over Slack. He confidently mentioned that it’s the best code ever, but honestly, I’m having a really hard time wrapping my head around it. I’ve
🌐
Cppreference
en.cppreference.com › w › cpp › language › while.html
while loop - cppreference.com
If it can be syntactically resolved as an expression, it is treated as an expression. Otherwise, it is treated as a declaration that is not a structured binding declaration(since C++26).
🌐
Quora
quora.com › Why-is-the-range-for-loop-not-working-properly-after-running-C-s-own-insert-function
Why is the range-for-loop not working properly after running C++’s own insert function? - Quora
Answer (1 of 7): Not sure exactly what you mean by the [code ]insert()[/code] function, but as a guess it may be that you are not paying attention to the restrictions on an [code ]insert()[/code] method, namely iterator invalidation. For a [code ]std::vector[/code] or [code ]std::deque[/code] an ...
🌐
Programiz
programiz.com › cpp-programming › for-loop
C++ for Loop (With Examples)
In this tutorial, we will learn about the C++ for loop and its working with the help of some examples. Loops are used to repeat a block of code for a certain number of times.
🌐
O'Reilly
oreilly.com › library › view › c-in-a › 059600298X › ch04s05.html
4.5. Loops - C++ In a Nutshell [Book]
The init, condition, and interate-expr parts are all optional. If the init or iterate-expr parts are omitted, nothing happens to initialize the loop or after the statement executes. If the condition is omitted, it defaults to true. The do statement is like a while statement, except that it tests at the end of the loop body. The syntax is: ... The statement is executed, then the expression ...