Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loop from/to has inconsistent behaviour #330

Open
lesquoyb opened this issue Sep 17, 2024 · 1 comment · May be fixed by #374
Open

Loop from/to has inconsistent behaviour #330

lesquoyb opened this issue Sep 17, 2024 · 1 comment · May be fixed by #374
Labels
😱 Bug The issue reveals a bug in GAMA

Comments

@lesquoyb
Copy link
Contributor

Describe the bug
I noticed some weird behaviours/inconsistency of the loop statement with the syntax from/to

  1. When doing a loop from 0 to 0 setting explicitly the step to 1, the loop goes through 0.0, a float, which is inconsistent with all the other cases where the type of the value over which we are iterating depends on those of from, to and step.
  2. When doing a loop from 0 to -1 setting explicitly the step to 1, the loop doesn't execute the code inside, which to me makes sense but is inconsistent with the previous example where we go through the loop at least once with the initial value.

To Reproduce
Steps to reproduce the behavior:

  1. Run this model:

model bugloopto

experiment a {
	init {
		write "from 0 to 1";
		loop i from:0 to:1 step:1{
			write i;
		}
		
		write "from 0 to 0";
		loop i from:0 to:0 step:1{
			write i;
		}
		
		write "from 0 to -1";
		loop i from:0 to:-1 step:1{
			write i;
		}
	}
}
  1. See error
@lesquoyb lesquoyb added the 😱 Bug The issue reveals a bug in GAMA label Sep 17, 2024
@hqnghi88
Copy link
Member

  1. it should be mistaken condition or unclear logic somewhere in the cases of process these combination.
  2. for me it is consistent to be as current because step is positive 1 so the loop never reach -1, if you change to step:-1, it works.

AlexisDrogoul added a commit that referenced this issue Nov 19, 2024
Separates the int and float bounded definitions. Makes a loop where "from" > "to" at least execute once with the value of "from".
@AlexisDrogoul AlexisDrogoul linked a pull request Nov 19, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
😱 Bug The issue reveals a bug in GAMA
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants