Thread: what is this doing??

  1. #1
    Registered User
    Join Date
    Apr 2004
    Posts
    1

    what is this doing??

    I have been looking at code for a magic square problem and have no idea what this code is doing. Could you guys please help me?

    Code:
    for (count = 2; count <= max_count; count++)
        {
        row = (i - 1 < 0) ? (size - 1) : (i - 1);  // up
        col = (j - 1 < 0) ? (size - 1) : (j - 1);  // left
    
    
    //i know what this is doing just need help with the above
    
    
        if (square[row][col] != 0)
          {
          i ++;
          i = i % size;
          }
        else
          {
          i = row;
          j = col;
          }
        square[i][j] = count;
        }

  2. #2
    Registered User axon's Avatar
    Join Date
    Feb 2003
    Posts
    2,572
    its another way of saying if else...

    some entropy with that sink? entropysink.com

    there are two cardinal sins from which all others spring: Impatience and Laziness. - franz kafka

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    As in
    Code:
    if ( i - 1 < 0 ) {
      row = size - 1;
    } else {
      row = i - 1;
    }
    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.

Popular pages Recent additions subscribe to a feed