04.06.2014, 19:22
It depends.
For example, if you want to loop through all the indexes of an array, using sizeof will be correct (not that it shouldn't be "<= sizeof (...);" because that will cause run time error 4. You'll need to use either "<" or "!=". Also indexes on arrays start always from 0 and not 1.
If you have an array (such as for houses - an example) and you want to loop only through the houses that exist, then if you store in a global variable how many houses there are, you can loop using the first one (without the '=' sign as I mentioned above).
For example, if you want to loop through all the indexes of an array, using sizeof will be correct (not that it shouldn't be "<= sizeof (...);" because that will cause run time error 4. You'll need to use either "<" or "!=". Also indexes on arrays start always from 0 and not 1.
If you have an array (such as for houses - an example) and you want to loop only through the houses that exist, then if you store in a global variable how many houses there are, you can loop using the first one (without the '=' sign as I mentioned above).