Iteration

This is a discussion on Iteration within the C Programming forums, part of the General Programming Boards category; What is the value of variable i and of variable j on line 4 below: Code: Line Code 1 j=0; ...

  1. #1
    Registered User
    Join Date
    Sep 2007
    Posts
    54

    Iteration

    What is the value of variable i and of variable j on line 4 below:

    Code:
    Line  Code
    1    j=0;
    2    for(i=0; i<10;i+=3)
    3         j=j+2;
    4    // What is the value of variable i and variable j?
    Is this how it iterates:
    i j
    0 0
    3 2
    6 4
    9 6


    therefore i=9 and j=6 ?????

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,422
    What happened to just trying it out?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,313
    Check for yourself by printing them out. Note that line 4 is after the loop.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  4. #4
    Registered User
    Join Date
    Sep 2007
    Posts
    54
    unfortunatley i dont have a compiler

    but i think i get it.

    i = 0
    j = 2
    i = 3
    j = 4
    i = 6
    j = 6
    i = 9
    j = 8

    Therefore j = 8 i = 12

    at uni we use linux and i think C90 compiler. where can i get a compiler similar to that but for windows vista

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Iteration?
    By Aliaks in forum C++ Programming
    Replies: 2
    Last Post: 06-06-2009, 11:17 PM
  2. MPI - linear pipeline solution for jacobi iteration
    By eclipt in forum C++ Programming
    Replies: 1
    Last Post: 05-03-2006, 05:25 AM
  3. recursivity & iteration
    By Marlon in forum C++ Programming
    Replies: 2
    Last Post: 06-14-2005, 01:58 PM
  4. The "continue" statement in JAVA
    By Hexxx in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 02-26-2004, 05:19 PM
  5. Iteration help please
    By incognito in forum C++ Programming
    Replies: 3
    Last Post: 12-09-2001, 06:37 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21