Page 1 of 1

FOR loop

Posted: December 3rd, 2022, 2:11 am
by matenek
Hello community.
I need to ask how many buildings there are in a school and for each building, fill in the same questions.

what the number of buildings of school? nr_buildings

if nr_buildings = 3
run loop 3 times with the same questions:
q1
q2
q3
q4
q5
end loop

Has anyone implemented this in cspro? what is the best way to receive the value in a variable and make the loop bringing the same questions to each building?

Best ;)

Re: FOR loop

Posted: December 5th, 2022, 9:40 am
by Gregory Martin
Typically you'd create a record for these building questions and then make the record repeat: https://www.csprousers.org/help/CSPro/occurrences.html

The NR_BUILDINGS value would not be on the repeating building record, as you're only asking that once. Then in Q1, you'd have a check, something like:
PROC Q1

preproc

    if curocc
() > NR_BUILDINGS then
        endgroup
;
    endif;

Re: FOR loop

Posted: December 5th, 2022, 8:49 pm
by matenek
Hi Gregory,
I already implemented your suggestion in tests and now works fine.

Thanks a lot.