Link to home
Start Free TrialLog in
Avatar of thomasmutton
thomasmuttonFlag for United Kingdom of Great Britain and Northern Ireland

asked on

C# for loop

Hello experts.

I have a for loop that works great but I want the first number to be one instead of zero.

how would I do this?
for (int i = 0; i < ds.Tables["tbl_trainingmodulesquestions"].Rows.Count; i++)
{
       i.tostring();
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of CyrexCore2k
CyrexCore2k
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial

for (int i = 1; i <= ds.Tables["tbl_trainingmodulesquestions"].Rows.Count; i++)
{
       i.tostring();
}

Open in new window

oxyoo that will execute the loop once less than the number of rows in the table which I don't think he wants.
Oh I see the <=

Instead he'll get an array index out of bounds when he tries ds.Tables["tbl_trainingmodulesquestions"].Rows[i]....
sorry, this should work better..


for (int i = 1; i < ds.Tables["tbl_trainingmodulesquestions"].Rows.Count; i++)
{
       i.tostring();
}

Open in new window

Ok, I see your point CyrexCore2k.
Avatar of thomasmutton

ASKER

Brilliant. Thanks alot.