You need to sign in to do that
Don't have an account?
Leonard Cadet
Nested For Loop Issue
I am trying to create a loop that creates pallet locations and puts that information into a record.
The first loop goes through the Section which is 1 to 46
The nested loop goes through the Aisle which is A to Q
I expect to start with the first section and then complete all the aisle before going back to iterating the through the Section again
So when the loop starts I expected it to start the section at 1 and loop through the Aisle like so:
A1A
B1A
C1A
etc
then once it hits q it loops out, increases the section by 1 and does the nested loop again
A2A
B2A
C2A
Can I get feedback on my code?
The first loop goes through the Section which is 1 to 46
The nested loop goes through the Aisle which is A to Q
I expect to start with the first section and then complete all the aisle before going back to iterating the through the Section again
So when the loop starts I expected it to start the section at 1 and loop through the Aisle like so:
A1A
B1A
C1A
etc
then once it hits q it loops out, increases the section by 1 and does the nested loop again
A2A
B2A
C2A
Can I get feedback on my code?
List<Stock_Location__c > slnewt = new List <Stock_Location__c>(); StringBuilder sb = new StringBuilder(); for (Integer i = 1; j = 0; i < 46; i++) { for(char alphabet = 'a'; alphabet <= 'q'; alphabet++) { Stock_Location__c slnewt = new Stock_Location__c( Aisle__c = sb.append(alphabet), Section__c = i , Shelf__c = 'a', barcode__c = sb.append(alphabet) + i + 'a', Location_Name__c = sb.append(alphabet) + '-' i+ '-'+ 'a' ); } slnewt.add(slnew); } Insert slnewt;
Hi,
you can use below code to generate your sequence A1A, B1A... etc
it will debug this
I hope this will help you. Please mark it best answer if it helps you.
All Answers
Hi,
you can use below code to generate your sequence A1A, B1A... etc
it will debug this
I hope this will help you. Please mark it best answer if it helps you.
r. Thank you!