Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

User-friendliness is what really matters

Name: Anonymous 2009-02-27 15:55

on space_check(threshold_percentage)
    tell application "Finder"
        set the percent_free to ¬
            (((the free space of the startup disk) / ¬
                (the capacity of the startup disk)) * 100) div 1
    end tell
    if the percent_free is less than the threshold_percentage then
        tell application (path to frontmost application as text)
            display dialog "The startup disk has only " & the percent_free & ¬
                " percent of its capacity available." & return & return & ¬
                "Should this script continue?" with icon 1
        end tell
    end if
end space_check

Name: Anonymous 2009-02-28 2:48

>>15

declare a variable of type integer called x that contains a value of 0 and has a local scope;
repeat the following single line of code until my integer variable called x contains an integer value equal to that of the integer literal value 100:
   increment the value of my integer variable called x by an integer value of 1;
output to the user console a line of text that contains the following literal string value "the value of x is " and the integer variable value of my integer variable x and a line break;


vs

public class Loop {
    public static void main(String[] args) {
        Loop myLoop = LoopFactory.getInstance(0,100,Loop.ASCENDING);
        while(myLoop.hasNext()) {
            System.out.println(myLoop.getLoopPosition());
            myLoop.incrementPosition();
        }
    }
    public static final int ASCENDING = 1;
    public static final int DESCENDING = -1;
    private int min;
    private int max;
    private int direction;
    private int current;
    protected Loop() {}
    public static Loop getNewLoop(int min, int max, int direction) {
        Loop self = new Loop();
        self.setLoopMin(min);
        self.setLoopMax(max);
        self.setLoopDirection(direction);
        int startPos = direction==Loop.ASCENDING?min:max;
        self.setLoopPosition(startPos);
    }
    public void setLoopMax(int max) {
        this.max = max;
    }
    public void setLoopMin(int min) {
        this.min = min;
    }
    public void setLoopPosition(int position) {
        this.current = position;
    }
    public void setLoopDirection(int direction) {
        this.direction = direction;
    }
    public int getLoopPosition() {
        return this.current;
    }
    public boolean hasNext() {
        if(direction==Loop.ASCENDING && Loop.current==max) return false;
        if(direction==Loop.DESCENDING && Loop.current==min) return false;
        return true;
    }
    public void incrementPosition() {
        this.current+=this.direction;
    }
    public static class LoopFactory {
        protected LoopFactory() {}
        public Loop getInstance() {
            return getInstance(0,0,1);
        }
        public Loop getInstance(int min, int max, int direction) {
            return Loop().getNewLoop(min,max,direction);
        }
    }
}


it's a tough decision; i know

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List