For loop reads second parameter as first along with first parameter...

So I did a test code for changing colors and stuff, and it compiles right, but I'm having a problem, first look at the code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>
#include <windows.h>
using namespace std;

int main () {
    const WORD colors[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F };
    HANDLE hOut;
    hOut = GetStdHandle (STD_OUTPUT_HANDLE);
    while (1) {
          for (short int x=0;x=14;x++) {
              SetConsoleTextAttribute (hOut, colors[x]);
              cout << "\t\t\t\t " << x + 1<< " \t\t\t\t " << endl;
              Sleep (1000);
          }
    }
    return 0;
}


it should print each number from 1 to 15 in a different color, but x in this loop is 14 all the time, and it'll never stop looping. I guess it's because the loop thinks the first parameter are short int x=0; and x=14;? I have no idea on how to solve this, nor even google it.
for (short int x=0;x=14;x++)
change to
for (short int x=0;x<15;x++)
Take a look at the for loop section on this page.

http://www.cplusplus.com/doc/tutorial/control/
Thanks!
Topic archived. No new replies allowed.