Jump to content

Odd but working syntax


Recommended Posts

Check the following example:

#cs
    This:
    If (conditon) Then
        (do this...)

    To:
    (condtion) And (do this...)

    Example:
    (True) And MsgBox(0, "", "")
#ce

#cs
    This:
    If (Not condtion) Then
        (do this...)

    To:
    (Not condition) Or (do this...)

    Example:
    (False) Or MsgBox(0, "", "")
#ce

;--------------------------------------------------

;This
If (FileExists(@ScriptFullPath)) Then
    MsgBox(0, "Standard", "Exist")
EndIf

;To
(FileExists(@ScriptFullPath)) And MsgBox(0, "Short", "Exist")

;This
If (Not IsAdmin()) Then
    MsgBox(0, "Standard", "You are not admin")
EndIf

;To
(IsAdmin()) Or MsgBox(0, "Short", "You are not admin")
Link to comment
Share on other sites

This is not odd - this is boolean algebra.  ;)

Have a look here -> http://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Examples

Checkout the return values of each functions and compare it with the boolean table for and ()/ or().

 

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

Well, I know about Boolean algebra, I had passed Boolean algebra in Discrete Mathematics in my previous term!

I call it odd because I didn't see anyone using this syntax, however in my opinion it's clear, simple and useful.

Also noticed that this kind of syntax usually got used in PHP.

Edited by D4RKON3
Link to comment
Share on other sites

Oops no, just wanted to share it with the community as I never seen anyone do this before.

Now that you are here, do you know anything about any performance issues with this syntax? As I remember, there was a little different in speed of one line If () Then ... and the Standard If () Then ... EndIf statements.

Edit:

 

I allowed it with one of the commits some time ago while I was active in development.

It seems like there is a sign of you everywhere! ;)

Edited by D4RKON3
Link to comment
Share on other sites

hey, look at that:

$iTimer = TimerInit()
For $i = 0 To 10000000
    If True Then $something=$i
Next
ConsoleWrite(TimerDiff($iTimer) & @CRLF)

$iTimer = TimerInit()
For $i = 0 To 10000000
    If True Then
        $something=$i
    EndIf
Next
ConsoleWrite(TimerDiff($iTimer) & @CRLF)

output:

19146.2078164728
10066.2411395331

That seems to be a significant difference.

Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

Here we go:

Global $something

$iTimer = TimerInit()
For $i = 0 To 10000000
    If True Then $something = $i
Next
ConsoleWrite(TimerDiff($iTimer) & @CRLF)

$iTimer = TimerInit()
For $i = 0 To 10000000
    If True Then
        $something = $i
    EndIf
Next
ConsoleWrite(TimerDiff($iTimer) & @CRLF)

$iTimer = TimerInit()
For $i = 0 To 10000000
    (True) And $something = $i
Next
ConsoleWrite(TimerDiff($iTimer) & @CRLF)
12924.9980183691
7313.35217241744
9594.36602411256
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...