Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

looping and other syntax

artistahin21artistahin21 Member Posts: 2
I use to know C and C++ before.. but that was 10 years ago, i am reading some post and answers and i am recalling how it is done. I just have a hard time in recalling switch and loops. Please help.

Comments

  • nermus50nermus50 Member Posts: 17
    loop 1: while

    [code]
    while(a<5)
    {
    //this code will execute only if condition is met
    }
    [/code]

    loop 2: do while
    [code]
    do
    {
    //this code will execute at least once then check for condition
    }while(a<5);
    [/code]
    loop3: for loop
    [code]
    for(int i=0;i<5;i++)
    {
    //this code will execute 5 times (i=0,i=1,i=2,i=3,i=4)
    //initialize i to starting value, check condition, change controller
    //i++ is equivalent to i=i+1
    }
    [/code]

    switch:
    [code]
    int a=0;
    switch(a)
    {
    case 1: //code executes if a==1
    break; //important!
    case 2: //code executes if a==2
    break;
    .
    .
    .
    default: //code executes if none of the other cases where true;
    break; //ok but not important
    }

    [/code]
Sign In or Register to comment.