create account

Turtle Programming v0.0.5: Adding IF/ELSE and STOP! by justyy

View this thread on: hive.blogpeakd.comecency.com
· @justyy · (edited)
$65.55
Turtle Programming v0.0.5: Adding IF/ELSE and STOP!
## Introduction to Logo Turtle
[LogoTurtle](https://helloacm.com/turtle-programming-v0-0-5-adding-if-else-and-stop/) is the first and currently only one Chrome Extension for Turtle Graphics.  I have also written [a PHP version of Logo Interpreter](https://steakovercooked.com/Software.Logo) in 2006 but that runs only on the server.

## Previous Contributions
- v0.0.4: [LogoTurtle: Make Variables and Comments](https://helloacm.com/logoturtle-make-variables-and-comments/)
- v0.0.3: [Turtle Graphics Programming Update: Adding text, jump, dot, fontsize, download as png](https://helloacm.com/turtle-graphics-programming-update-adding-text-jump-dot-fontsize-download-as-png/)
- v0.0.2: [LogoTurtle v0.0.2: ShowTurtle, HideTurtle, Color, Width and Help](https://helloacm.com/logoturtle-v0-0-2-showturtle-hideturtle-color-width-and-help/).
- Teach Your Kids Programming - The First Logo Interpreter (Turtle Graphics) in Chrome Extension!
 [v0.0.1](https://helloacm.com/teach-your-kids-programming-the-first-logo-interpreter-turtle-graphics-in-chrome-extension/)

## v0.0.5 New Features
[**This Commit**](https://github.com/DoctorLai/LogoTurtle/commit/c960f5ea159b4475282aa566bcf3005c0323afe4) supports **IF/ELSE** and **STOP**.

In previous versions, the LOOP program flow is supported by keyword **REPEAT** and the most important IF/ELSE is now implemented in this version.

## Screenshots
This is how things get a little bit interesting and I believe now you can have your imaginations fly.

![image.png](https://res.cloudinary.com/hpiynhbhq/image/upload/v1519885299/ql5utq6uoqdzdpa4lhia.png)
```
ht cs make "a 1 repeat 8 [pu fd 100 pd 
repeat 12 [
  if :a%3==1 [rt 90] else [lt 90] 
  fd 30 make "a :a+1
] pu bk 100 rt 45]
```

# How to Implement IF/ELSE in Logo/Javascript?
The IF part is similar to REPEAT and all we need to do is to parse the ELSE part.

```
case "if":
expr = this.evalVars(word_next, true);
try {
	word_next = eval(expr);
} catch (e) {
	this.pushErr(LOGO_ERR_EVAL, expr);
	return false;
}				
if ((word_next === '')) {						
	this.pushErr(LOGO_ERR_MISSING_EXP, word_next);
	return false;
}
find_left = getNextWord(s, y.next, U);
if (find_left.word != '[') {
	this.pushErr(LOGO_ERR_MISSING_LEFT, find_left.word);
	return false;
}
repeat_left = find_left.next;
find_right = repeat_left + 1;
nested = 1;
// need to match [ and ]
while (find_right < U) {
	if (s[find_right] == '[') {
		nested ++;
	}												
		if (s[find_right] == ']') {
			nested --;
			if (nested == 0) {
				break;
			}
		}
		find_right ++;
}
if (find_right >= U) {
	this.pushWarning(LOGO_ERR_MISSING_RIGHT);						
}
let ifelse = word_next;					
if (ifelse) {
	// if body
	if (!this.run(s, repeat_left, find_right, depth + 1)) {
		return false;
	}
} 	
find_else = getNextWord(s, find_right + 1, U);
if (find_else.word.toLowerCase() == 'else') {
	let else_block = getNextBody(s, find_else.next, U);
	if (else_block.ch != '[') {
		this.pushErr(LOGO_ERR_MISSING_LEFT, else_block.ch);
		return false;
	}
	if (!ifelse) {
		// else body
		if (!this.run(s, else_block.left, else_block.right, depth + 1)) {
			return false;
		}
	}
	i = else_block.right + 1;
} else {
	// no else block
	i = find_right + 1; 
}
break;	
```

## Roadmap of Chrome Extension: Logo Turtle
1. Add Functions
2. Add IF/THEN/ELSE
3. Add Variables
4. Add Colors
5. Add MoveTo
6. Add PrintText
7. Add Circle
8. Add Arc
9. Add Eraser
10. Add Fill
11. Save As Picture
12. Save As Program
13. Comments
14. Add Recursion Support
15. Add Global/Local Scopes
16. etc. etc.

## Technology Stack
If an App can be written in [Javascript](https://helloacm.com/steemit-javascript-function-to-get-original-post-from-comments-permlink/), eventually it will be written in Javascript.

# Chrome Webstore
Install the [Turtle Programming for Kids](https://chrome.google.com/webstore/detail/logo-turtle/dcoeaobaokbccdcnadncifmconllpihp) Now!

# Contribution Welcome
Github: https://github.com/DoctorLai/LogoTurtle
1. Fork it!
2. Create your feature branch: `git checkout -b my-new-feature`
3. Commit your changes: `git commit -am 'Add some feature'`
4. Push to the branch: `git push origin my-new-feature`
5. Submit a pull request.

<br /><hr/><em>Posted on <a href="https://utopian.io/utopian-io/@justyy/turtle-programming-v0-0-5-adding-if-else-and-stop">Utopian.io -  Rewarding Open Source Contributors</a></em><hr/>
👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , and 119 others
properties (23)
authorjustyy
permlinkturtle-programming-v0-0-5-adding-if-else-and-stop
categoryutopian-io
json_metadata{"community":"utopian","app":"steemit/0.1","format":"markdown","repository":{"id":121791502,"name":"LogoTurtle","full_name":"DoctorLai/LogoTurtle","html_url":"https://github.com/DoctorLai/LogoTurtle","fork":false,"owner":{"login":"DoctorLai"}},"pullRequests":[],"platform":"github","type":"development","tags":["utopian-io","steemstem","programming","steemdev","cn-programming"],"links":["https://helloacm.com/turtle-programming-v0-0-5-adding-if-else-and-stop/","https://steakovercooked.com/Software.Logo","https://helloacm.com/logoturtle-make-variables-and-comments/","https://helloacm.com/turtle-graphics-programming-update-adding-text-jump-dot-fontsize-download-as-png/","https://helloacm.com/logoturtle-v0-0-2-showturtle-hideturtle-color-width-and-help/","https://helloacm.com/teach-your-kids-programming-the-first-logo-interpreter-turtle-graphics-in-chrome-extension/","https://github.com/DoctorLai/LogoTurtle/commit/c960f5ea159b4475282aa566bcf3005c0323afe4","https://helloacm.com/steemit-javascript-function-to-get-original-post-from-comments-permlink/","https://chrome.google.com/webstore/detail/logo-turtle/dcoeaobaokbccdcnadncifmconllpihp","https://github.com/DoctorLai/LogoTurtle","https://utopian.io/utopian-io/@justyy/turtle-programming-v0-0-5-adding-if-else-and-stop"],"image":["https://res.cloudinary.com/hpiynhbhq/image/upload/v1519885299/ql5utq6uoqdzdpa4lhia.png"],"moderator":{"account":"ms10398","time":"2018-03-01T11:03:32.731Z","reviewed":true,"pending":false,"flagged":false},"questions":[],"score":0}
created2018-03-01 06:24:24
last_update2018-03-02 08:52:30
depth0
children5
last_payout2018-03-08 06:24:24
cashout_time1969-12-31 23:59:59
total_payout_value48.424 HBD
curator_payout_value17.122 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length4,355
author_reputation280,616,224,641,976
root_title"Turtle Programming v0.0.5: Adding IF/ELSE and STOP!"
beneficiaries
0.
accountutopian.pay
weight2,500
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id41,306,183
net_rshares15,515,505,814,182
author_curate_reward""
vote details (183)
@bobdos ·
upvote
properties (22)
authorbobdos
permlinkre-justyy-turtle-programming-v0-0-5-adding-if-else-and-stop-20180301t092750138z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"app":"steemit/0.1"}
created2018-03-01 09:27:51
last_update2018-03-01 09:27:51
depth1
children0
last_payout2018-03-08 09:27:51
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length6
author_reputation7,506,600,424,421
root_title"Turtle Programming v0.0.5: Adding IF/ELSE and STOP!"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id41,337,331
net_rshares0
@ms10398 ·
Thank you for the contribution. It has been approved.

You can contact us on [Discord](https://discord.gg/uTyJkNm).

**[[utopian-moderator]](https://utopian.io/moderators)**
properties (22)
authorms10398
permlinkre-justyy-turtle-programming-v0-0-5-adding-if-else-and-stop-20180301t110350941z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"community":"utopian","app":"utopian/1.0.0"}
created2018-03-01 11:03:51
last_update2018-03-01 11:03:51
depth1
children0
last_payout2018-03-08 11:03:51
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length173
author_reputation27,572,487,973,390
root_title"Turtle Programming v0.0.5: Adding IF/ELSE and STOP!"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id41,354,253
net_rshares0
@steemstem-bot ·
$0.72
<center><a href="www.steemit.com/@steemstem"><img src="https://media.discordapp.net/attachments/384404201544876032/405507994583957505/steemSTEM.png"></a><br><table><tr><th> </th><th> </th><th><a href="https://steemit.com/steemstem/@steemstem/helpful-guidelines-for-crafting-steemstem-content">Guidelines</a></th><th><a href="https://steemit.com/steemstem/@steemstem/steemstem-winter-2017-2018-project-update">Project Update</a></th><th> </th><th> </th></tr></table><br><a href="https://steemit.com/steemstem/@steemstem/being-a-member-of-the-steemstem-community"><b>Being A SteemStem Member</b></a></center>
👍  
properties (23)
authorsteemstem-bot
permlinkre-turtle-programming-v0-0-5-adding-if-else-and-stop-20180301t223909
categoryutopian-io
json_metadata""
created2018-03-01 22:39:09
last_update2018-03-01 22:39:09
depth1
children1
last_payout2018-03-08 22:39:09
cashout_time1969-12-31 23:59:59
total_payout_value0.722 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length606
author_reputation3,811,533,615,496
root_title"Turtle Programming v0.0.5: Adding IF/ELSE and STOP!"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id41,487,787
net_rshares141,891,748,102
author_curate_reward""
vote details (1)
@justyy ·
thank you very much, that means a lot to me :)
properties (22)
authorjustyy
permlinkre-steemstem-bot-re-turtle-programming-v0-0-5-adding-if-else-and-stop-20180301t223909-20180302t170433133z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"app":"steemit/0.1"}
created2018-03-02 17:04:33
last_update2018-03-02 17:04:33
depth2
children0
last_payout2018-03-09 17:04:33
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length46
author_reputation280,616,224,641,976
root_title"Turtle Programming v0.0.5: Adding IF/ELSE and STOP!"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id41,678,854
net_rshares0
@utopian-io ·
### Hey @justyy I am @utopian-io. I have just upvoted you!
#### Achievements
- WOW WOW WOW People loved what you did here. GREAT JOB!
- Seems like you contribute quite often. AMAZING!
#### Community-Driven Witness!
I am the first and only Steem Community-Driven Witness. <a href="https://discord.gg/zTrEMqB">Participate on Discord</a>. Lets GROW TOGETHER!
- <a href="https://v2.steemconnect.com/sign/account-witness-vote?witness=utopian-io&approve=1">Vote for my Witness With SteemConnect</a>
- <a href="https://v2.steemconnect.com/sign/account-witness-proxy?proxy=utopian-io&approve=1">Proxy vote to Utopian Witness with SteemConnect</a>
- Or vote/proxy on <a href="https://steemit.com/~witnesses">Steemit Witnesses</a>

[![mooncryption-utopian-witness-gif](https://steemitimages.com/DQmYPUuQRptAqNBCQRwQjKWAqWU3zJkL3RXVUtEKVury8up/mooncryption-s-utopian-io-witness-gif.gif)](https://steemit.com/~witnesses)

**Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x**
properties (22)
authorutopian-io
permlinkre-justyy-turtle-programming-v0-0-5-adding-if-else-and-stop-20180302t015133487z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"community":"utopian","app":"utopian/1.0.0"}
created2018-03-02 01:51:33
last_update2018-03-02 01:51:33
depth1
children0
last_payout2018-03-09 01:51:33
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length1,061
author_reputation152,955,367,999,756
root_title"Turtle Programming v0.0.5: Adding IF/ELSE and STOP!"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id41,518,521
net_rshares0