ILoveC4 Posted May 17, 2009 Share Posted May 17, 2009 When is it appropriate to use the "break" command? Also, when is the "stop" command most often used? I can only think of one instance where I use the stop command, and if I understand it correctly it ends the script them, right?Example:IF xxxxxxx then yyyyyyy STOPIF zzzzzzzz then aaaaaaa STOPWould the STOP command stop the second IF statement from being checked, or would it only stop something nested below the stop statement? Link to comment Share on other sites More sharing options...
henniae Posted May 17, 2009 Share Posted May 17, 2009 When is it appropriate to use the "break" command? Also, when is the "stop" command most often used? I can only think of one instance where I use the stop command, and if I understand it correctly it ends the script them, right?Example:IF xxxxxxx then yyyyyyy STOPIF zzzzzzzz then aaaaaaa STOPWould the STOP command stop the second IF statement from being checked, or would it only stop something nested below the stop statement?In your example above the first stop command would prevent the second IF statement from running if the first IF statement was executed. Link to comment Share on other sites More sharing options...
ILoveC4 Posted May 17, 2009 Author Share Posted May 17, 2009 Thank you, that is what I thought.How about the break command? Link to comment Share on other sites More sharing options...
thecodeman Posted May 17, 2009 Share Posted May 17, 2009 The break command is used when you want to break out of a nested (indented) command and go one out to the left. "Break out" to the left. Link to comment Share on other sites More sharing options...
zaphod Posted May 20, 2009 Share Posted May 20, 2009 Using commands of these sort would get you an F in CompSci 101 in my days. Very bad programming habits! Link to comment Share on other sites More sharing options...
RyanE Posted May 20, 2009 Share Posted May 20, 2009 Yeah, in my day, nothing but a GOTO was needed!Actually, it was probably a JMP and/or LONGJMP, in assembly, of course.Seriously, Break is pretty common (it's also called 'continue' in some languages), and Stop is nothing but a 'return'.The reason they're somewhat awkward is that there's no 'else' in the drag and drop programming, so you have to use if...then and then break to implement an else.RyanE Link to comment Share on other sites More sharing options...
CFUG Posted May 20, 2009 Share Posted May 20, 2009 Ryan, could you give example of a simple routine using break- having a hard time imagining how/when to use- thanks Link to comment Share on other sites More sharing options...
RyanE Posted May 20, 2009 Share Posted May 20, 2009 I don't have any ready examples here at work, but I could possibly scare some up later at home.RyanE Link to comment Share on other sites More sharing options...
shaneoneill Posted May 21, 2009 Share Posted May 21, 2009 Yeah, in my day, nothing but a GOTO was needed!Actually, it was probably a JMP and/or LONGJMP, in assembly, of course.Seriously, Break is pretty common (it's also called 'continue' in some languages), and Stop is nothing but a 'return'.The reason they're somewhat awkward is that there's no 'else' in the drag and drop programming, so you have to use if...then and then break to implement an else.RyanEwhich brings me to my next question....always wondered about the absence of else...could it go in sometime in the future? Link to comment Share on other sites More sharing options...
RyanE Posted May 21, 2009 Share Posted May 21, 2009 I suppose in theory, there's nothing keeping it from going in, but I doubt that it's anywhere on *anyone's* radar.RyanE Link to comment Share on other sites More sharing options...
ILoveC4 Posted May 21, 2009 Author Share Posted May 21, 2009 Any examples of using that break command? Link to comment Share on other sites More sharing options...
thecodeman Posted May 21, 2009 Share Posted May 21, 2009 Here's how I would use it.When the Variable Current Media Changes in Room->ILoveC4's Party Shack IF Current Media Selction = "Vanilla Ice" -> STOP "CollaborateAndListen" -> BREAK IF Current Media Selection = "MC Hammer" -> STOP "HammerTime" -> BREAK (it down)While "HammerTime" is TRUE -> LOOP "ohohohoh" Link to comment Share on other sites More sharing options...
ILoveC4 Posted May 21, 2009 Author Share Posted May 21, 2009 Very funny codeman, that actually made me chuckle. Bonus points for creativity. I am serious though, does anyone have an example of this being used? Link to comment Share on other sites More sharing options...
RyanE Posted May 21, 2009 Share Posted May 21, 2009 I think thecodeman's example is certainly valid.An actual use of code won't be clearer as to when you should use it.The Vanilla Ice / MC Hammer part is pretty much equivalent to an if/then/elseif.RyanE Link to comment Share on other sites More sharing options...
bebster Posted May 21, 2009 Share Posted May 21, 2009 Here's an example of the break command (more like the java language than C4 script, but the logic is the same. Basically it cause you to break out of the loop after the first pass through.while ( i < 5) { i=doSomething(); if(i<0) break; // jump out of the loop }Google "java break command" for more examples.I know it's not a real life example of a C4 application of the command. Link to comment Share on other sites More sharing options...
Matt Posted May 21, 2009 Share Posted May 21, 2009 Bebster is correct, the 'Break' is to break out of a loop, no out of an 'if' statement.Good job Link to comment Share on other sites More sharing options...
thecodeman Posted May 21, 2009 Share Posted May 21, 2009 Bebster is correct, the 'Break' is to break out of a loop, no out of an 'if' statement.Good job OK I'll go back and re-review my training slides and correct my analogy accordingly Link to comment Share on other sites More sharing options...
ILoveC4 Posted May 21, 2009 Author Share Posted May 21, 2009 Here's an example of the break command (more like the java language than C4 script, but the logic is the same. Basically it cause you to break out of the loop after the first pass through.while ( i < 5) { i=doSomething(); if(i<0) break; // jump out of the loop }Google "java break command" for more examples.I know it's not a real life example of a C4 application of the command.Thanks Bebster, I understand how it works in Java. I was looking for that real life example of a C4 application of the command. Based on what Matt says it sounds like it is only used with loops? That would explain why I am unfamiliar with it, I have never used a loop and don't think it is even possible for me to program a loop.Is that true, that they are only used with loops? If not, I would still love an example. Link to comment Share on other sites More sharing options...
Matt Posted May 21, 2009 Share Posted May 21, 2009 Delay — Allows you to delay an action from taking place.Stop—Allows you to stop all programming.Break—Allows you to break out of a while loop when a specified condition is met and return to the programming outside of the loop.I am not going to show you in a while loop, I recommend against them. If programmed incorrectly you could really “jack up” your system. Stick with conditionals. Link to comment Share on other sites More sharing options...
ILoveC4 Posted May 21, 2009 Author Share Posted May 21, 2009 Thanks Matt, I am not looking for information on a while loop. I was mostly just curious if the "break" command had a use outside of the loop. I don't think I even have the ability to add loops, do I? Link to comment Share on other sites More sharing options...
Matt Posted May 21, 2009 Share Posted May 21, 2009 You’re correct, HE doesn’t have loops So break would do nothing for you…{but I know the real you} Link to comment Share on other sites More sharing options...
ILoveC4 Posted May 21, 2009 Author Share Posted May 21, 2009 {but I know the real you}We should talk about that when you get back in town. Link to comment Share on other sites More sharing options...
CFUG Posted May 21, 2009 Share Posted May 21, 2009 ^Yeah, I don't get this at all. You can only evaluate something once (like when a button is pressed). Looping doesn't seem possible or desirable as already mentioned. HC-1000 would be the "base model" controller in that case Link to comment Share on other sites More sharing options...
ILoveC4 Posted May 21, 2009 Author Share Posted May 21, 2009 ^Yeah, I don't get this at all. You can only evaluate something once (like when a button is pressed). Looping doesn't seem possible or desirable as already mentioned. HC-1000 would be the "base model" controller in that case I could see how it would be beneficial to create a makeshift timer before that was possible using the new agent. For example:To create a :60 second timer you could:When button three is released set variable "timer" to 60 ->Delay one second ->Variable "timer" = -1 ->If variable "timer" >0 LoopI don't know how the loop looks on programming, but that could be a way to create a timer where the length of timer was easily adjustable. Of course the timer agent makes this obsolete. I cannot even think of a time when using a loop would be desirable, and it sounds like the break command is only used in conjunction with a loop.Hell, while were at it does anyone have an example of what a loop might be used for? Link to comment Share on other sites More sharing options...
thecodeman Posted May 21, 2009 Share Posted May 21, 2009 This is how you could use a "loop". It's pretty complex imo and I can see how they would want to leave it out. Lots of things to think about, just for a bathroom fan on a timer like this.Yes, for example, make a button press turn on a fan, and then turn it off after a certain period of time. You can also increase the time the fan remains on in 5 minute increments.The timer variable is decremented like you described, but there's a delay of one second before the decrement for seconds. From training:Create two variables.In the enclosed example, these variables are named “MasterFanCount” and “MasterfanBL”To add 5 minutes to the fan time, increment the “MasterFanCount” numeric variable +300 and set the “MasterfanBL” Boolean variable to trueOnce we place a while loop = true on the MasterfanBL Boolean variable, we can set a delay of 1 second and decrement (minus) 1 from 300 each second.This represents a time object of 5 minutes each tap 300/60 = 5Programming looks like:When Master Bathroom - Bathroom Fan Top Button is pushedVariables MasterFanCount = MasterFanCount + 300 (this is seconds, giving you 5 minutes each tap)Variables MasterFanBL = TrueHere is the while statement made to the Boolean variableNotice the MasterFanCount numeric variable is being decremented by 1 each secondProgramming looks like:When the variable Variables-MasterFanBL changes(loop) While variables MasterFanBL is true delay 1 second variables-> MasterFanCount = Variables-> MasterFanCount -1 If the bathroom fan level changes, the conditional “If Light Off” will then set the boolean variable “MasterfanBL” to false the the numeric variable “MasterFanCount” to zero which turns off the fan.Problem this avoids:What if you turn off the fan from a Navigator? It doesn’t reset the count to a “0” and set the Boolean Variable to False as it should.Programming looks like:(On the Bathroom Fan Switch)When Master Bathroom -> Bathroom Fan Level changes? If Master Bathroom Light is off variables-> MasterFanBL = False variables-> MasterFanCount = 0If the bottom button on the switch is pushed, then the numeric variable “MasterFanCount” = 0Here is the conditional statement made to the numeric variable to turn off the fan.When the variable Variables->MasterFanCount changesIf Variables-> MasterFanCount<1 Variables->MasterFanBL = false Variables->MasterFanCount = 0 Turn Off the Master Bathroom -> Bathroom Fan Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.