question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Make while, for and if return values

See original GitHub issue

if is essentially a while loop that is executed once at most, however return values for if and while are inconsistent.

If returns the value of its last statement as its value:

🦄 .editor
// Entering editor mode (^D to finish, ^C to cancel)
if(true) {
  let b = 4 
}

int ask(if(call(get('true')),block(let('b',4)),block()))
4

However while always returns null:

🦄 .editor
// Entering editor mode (^D to finish, ^C to cancel)
let b = 2
while(b<4) {
  b = b+1 
}

empty ask(let('b',2),while(call(get('<'),get('b'),4),block(assign('b',call(get('+'),get('b'),1)))))
null
🦄 

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:14

github_iconTop GitHub Comments

1reaction
mhagmajercommented, Jun 27, 2020

So you’re thinking that while should be like reduce?

1reaction
czerwinskilukasz1commented, Jun 27, 2020

If I Recall Correctly

Read more comments on GitHub >

github_iconTop Results From Across the Web

Python How to Return value in while loop - Stack Overflow
Simply take your x=str(ser.readline()) x = re.findall("\d+\.\d+", x) x = float(x[0]) return(x) #loop stopped. put it into a function like
Read more >
Make while loop test result of function? - Codecademy
Hey guys, I'm trying to figure out how to make my while loop run based off of the result of the function: var...
Read more >
Return | Java Loop Statements - EXLskills
It is good practice to always have a return statement after the for/while loop in case the return statement inside the for/while loop...
Read more >
Javanotes 9, Section 4.4 -- Return Values
A subroutine that returns a value is called a function. ... function can even be used as the test condition in an if,...
Read more >
return - JavaScript - MDN Web Docs - Mozilla
When a return statement is used in a function body, the execution of the function is stopped. If specified, a given value is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found